import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter_socket_server/custom_icon_button.dart';
import 'package:flutter_socket_server/permission_utils.dart';
import 'package:flutter_socket_server/show_qr_page.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:flutter_socket_server/screen_util.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  int port;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      routes: <String, WidgetBuilder>{
        // 其中/a代表页面a
        '/a': (BuildContext context) => MyApp(),
        '/b': (BuildContext context) => ShowQRPage(),
      },
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {

  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() async {
    Permission.storage.request();
    setState(() {
      _counter++;
    });
  }

  /// 显示备份IM数据弹框
  static void _showIMBackupWidget(BuildContext context) async {
    showModalBottomSheet(
        context: context,
        backgroundColor:Colors.transparent,
        isScrollControlled: false,
        isDismissible: false,
        enableDrag: false,
        builder: (BuildContext context) {
          return ShowQRPage();
        });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            NiIconButton(
              onTap: () {
                _showIMBackupWidget(context);
              },
              child: Image.asset(
                'assets/icon/qr.png',
                width: 20.w,
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
